/*
 * MIT License
 *
 * Copyright (c) 2020 wen.gu <454727014@qq.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/***************************************************************************
 * Name: code_generator.h
 *
 * Purpose: code generator base class
 *
 * Developer:
 *   wen.gu , 2021-05-10
 *
 * TODO:
 *
 ***************************************************************************/

/******************************************************************************
 **    INCLUDES
 ******************************************************************************/
#ifndef __CODE_GENERATOR_H__
#define __CODE_GENERATOR_H__

#include <string>
#include <vector>

#include "file_content.h"

/******************************************************************************
 **    MACROS
 ******************************************************************************/


/******************************************************************************
 **    TYPE DEFINITIONS
 ******************************************************************************/

enum class GeneratorLanguageType: uint8_t
{
    kUnknown = 0x0,
    kCpp, /** generate cpp source code */
};

/** communication binding type */
enum class GeneratorCommunicationBinding: uint8_t
{
    kUnknown = 0x0,
    kFDBus,      /** binding to FD-Bus with default  serializer/deserializer */
    kFDBusProtobuf, /** binding to FD-Bus with protobuf serializer/deserializer */
};

struct SourceCodeFile
{
    std::string name;
    std::string content;
};

using SourceCodeFileArray = std::vector<SourceCodeFile>;
/******************************************************************************
 **    CLASSES/FUNCTIONS DEFINITIONS
 ******************************************************************************/

class CodeGenerator
{
protected:
    CodeGenerator(GeneratorLanguageType language, GeneratorCommunicationBinding binding_type);
public:  
    virtual ~CodeGenerator();

public:
    /**set the template path for code generate */
    virtual bool setFileTemplatePath(const std::string& code_template_path) = 0;
    virtual bool generate(const FileContent& file_content, SourceCodeFileArray& out_code) = 0;

public:
    GeneratorLanguageType language() const { return language_type_;}
    GeneratorCommunicationBinding binding() const { return binding_type_; }
    static CodeGenerator* Create(GeneratorLanguageType language, GeneratorCommunicationBinding binding_type);

protected:
    GeneratorLanguageType language_type_;
    GeneratorCommunicationBinding binding_type_; 
};

#endif /** !__CODE_GENERATOR_H__ */

